/**
 * 
 */
package game.kill.service.impl;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;

import game.kill.mapper.UserMapper;
import game.kill.model.User;
import game.kill.service.UserService;
import tk.mybatis.mapper.entity.Example;

/**
 * @author leiruiqi
 *
 */

@Service("userService")
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;
	
	@Override
	public void save(User user) {
		userMapper.insert(user);
	}

	@Override
	public User getById(Long userId) {
		return userMapper.selectByPrimaryKey(userId);
	}

	@Override
	public Map<Long, User> getUserMapByIds(Collection<Long> userIds) {
		Map<Long,User> userMap = Maps.newHashMap();
		if(CollectionUtils.isEmpty(userIds)){
			return userMap;
		}
		Example condition = new Example(User.class);
		condition.createCriteria().andIn("id", userIds);
		
		List<User> userList = userMapper.selectByExample(condition);
		
		for(User user:userList){
			userMap.put(user.getId(), user);
		}
		return userMap;
	}

	
}
